import {observer} from 'mobx-react';
import React from 'react';
import {withRouter, Route} from 'react-router-dom';
import * as EmSDK from '../util/emSDK';

@withRouter
@observer
class App extends React.Component {
    componentWillMount() {
        EmSDK.doInitEmSDK();
        EmSDK.resetEmElement();
    }
    componentWillReceiveProps(nextProps, nextState) {
        const location = this.props.location || {};
        const nextLocation = nextProps.location || {};
        if (location.pathname !== nextLocation.pathname) {
            EmSDK.resetEmElement();
            EmSDK.setEmTopNav(nextLocation.pathname);
        }
    }
    componentWillUnmount(){
        EmSDK.resetEmElement();
    }
    componentDidMount() {
        window.historyRoute = this.props.history;
    }
    render() {
        return this.props.children;
    }
}

export default App;